package com.xgame.server.dbtool;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.xgame.server.db.mapper.FuckiosMapper;
import com.xgame.server.db.mapper.PurgatoryMapper;
import com.xgame.server.db.model.Fuckios;
import com.xgame.server.netty.proto.Game;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class FuckiosCsTool {
    @Resource
    private FuckiosMapper fuckiosMapper;

    //插入经验副本
    public Integer insertIosData(Game.FuckIosCS data) throws Exception {

        //1.删除本玩家的所有
        deleteIos(data.getAccount());

        //2.插入
        List<Game.FuckIosOneCS> items = data.getListList();
        int length = items.size();
        Integer count = new Integer(0);
        for (int i = 0; i < length; i++) {
            Game.FuckIosOneCS one = items.get(i);
            Fuckios map = new Fuckios();
            map.setAccount(data.getAccount());
            map.setPlayerId(data.getPlayerID());
            map.setItemId(one.getItemId());
            map.setProductId(one.getProductId());
            map.setStatus(one.getStatus());
            map.setBid(one.getBid());
            map.setBvrs(one.getBvrs());
            map.setUniqueIdentifier(one.getUniqueIdentifier());
            map.setOriginalTransactionId(one.getOriginalTransactionId());
            map.setTransactionId(one.getTransactionId());
            map.setOriginalPurchaseDatePst(one.getOriginalPurchaseDatePst());
            map.setPurchaseDatePst(one.getPurchaseDatePst());
            map.setOriginalPurchaseDateMs(one.getOriginalPurchaseDateMs());
            map.setPurchaseDateMs(one.getPurchaseDateMs());
            map.setOriginalPurchaseDate(one.getOriginalPurchaseDate());
            map.setPurchaseDate(one.getPurchaseDate());
            map.setUniqueVendorIdentifier(one.getUniqueVendorIdentifier());
            map.setQuantity(one.getQuantity());
            map.setVersionExternalIdentifier(one.getVersionExternalIdentifier());

            count += fuckiosMapper.insert(map);
        }

        return count;
    }

    //删除记录
    public Integer deleteIos(String account) throws Exception {
        EntityWrapper<Fuckios> userWrapper = new EntityWrapper<>();
        userWrapper.eq("account", account);

        return fuckiosMapper.delete(userWrapper);
    }

    //查询记录
    public List<Fuckios> selectIosItem(String account) throws Exception {
        EntityWrapper<Fuckios> userWrapper = new EntityWrapper<>();
        userWrapper.eq("account", account);

        return fuckiosMapper.selectList(userWrapper);
    }

}
